/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bgu.sonar.util.ui.nodes;

import bgu.sonar.util.collections.CategoryMap;
import bgu.sonar.util.ui.visual.HasVisualData;
import bgu.sonar.util.ui.visual.VisualDataProvider;
import java.awt.Image;

/**
 *
 * @author bennyl
 */
public class CategoryNodeAttributes implements HasVisualData {

    private String name;
    private Image icon;
    private VisualDataProvider childrenVisualData;
    private ActionProvider childrenActionsProvider = null;
    private ActionProvider categoryActionsProvider = null;

    public void setCategoryActionsProvider(ActionProvider categoryActionsProvider) {
        this.categoryActionsProvider = categoryActionsProvider;
    }

    public ActionProvider getCategoryActionsProvider() {
        return categoryActionsProvider;
    }
    
    public void setChildrenActionsProvider(ActionProvider childrenActionsProvider) {
        this.childrenActionsProvider = childrenActionsProvider;
    }

    public ActionProvider getChildrenActionsProvider() {
        return childrenActionsProvider;
    }

    public CategoryNodeAttributes() {
    }

    public void setIcon(Image icon) {
        this.icon = icon;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setChildrenVisualData(VisualDataProvider childrenVisualData) {
        this.childrenVisualData = childrenVisualData;
    }

    public VisualDataProvider getChildrenVisualData() {
        return childrenVisualData;
    }

    @Override
    public String getVisualName() {
        return name;
    }

    @Override
    public Image getIcon() {
        return icon;
    }

    public void attach(CategoryMap ad) {
        ad.add(this, "node.attributes");
    }

    /**
     * can return null if no such exists
     *
     * @param from
     * @return
     */
    public static CategoryNodeAttributes extract(CategoryMap from) {
        CategoryMap folder = from.getChildCategory("node.attributes");
        if (folder != null && !folder.values().isEmpty() && folder.values().get(0) instanceof CategoryNodeAttributes) {
            return (CategoryNodeAttributes) folder.values().get(0);
        }

        return null;
    }

    @Override
    public String getDescription() {
        return "";
    }
}
